﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using AutoFacWrapper;
using ZL.WeChatCard.Entity;
using ZL.WeChatCard.Entity.EasyUse;
using ZL.WeChatCard.Entity.ViewModel;
using ZL.WeChatCard.Service;
using ZL.WeChatCard.Service.InterFace;

namespace ZLWeChatCard.Controllers
{
    public class ProfileController : BaseController
    {
        // GET: Profile
        public ActionResult Index()
        {
            var pservice = ClassFactory.GetInstance<IPaymentService>();
            AccInfo item = pservice.GetNo(OpenID);
            if (item == null)
            {
                return Redirect("~/Payment/Regesiter?act=Index&&contro=Profile");
                //return this.RedirectToAction("Regesiter", "Payment");
            }
            if (!item.IsSuccess) return Redirect("~/Payment/Regesiter?act=Index&&contro=Profile");
            return View("Index", new ProfileAccinfo() { cellno = item.Accname, dycardno= item.Dycardno });
        }

        [HttpPost]
        public ActionResult profileform(ProfileAccinfo page)
        {
            var rservice = ClassFactory.GetInstance<IProfileService>();
            ProfileAccinfoResponse accinfo = rservice.UpdateProfileAccInfo(page);
            if (!accinfo.IsSuccess)
            {
                page.Issuccess = false;
                page.errormsg=accinfo.Errormodel.desc;
                return Json(page);
            }
            page.Issuccess = true;
            return Json(page);
        }

        [HttpGet]
        public ActionResult Get()
        {
            var rservice = ClassFactory.GetInstance<IProfileService>();
            ProfileAccinfo accinfo= rservice.GetProfileAccinfoResponse(OpenID);
            if(accinfo==null) accinfo=new ProfileAccinfo();
            return Json(accinfo, JsonRequestBehavior.AllowGet);
        }
    }
}